package com.example.payer.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.payer.databinding.ItemPayer1Binding
import com.example.payer.databinding.ItemPayerBinding
import com.example.payer.etity.Payer

class PayerAdapter(private val data:List<Payer>):RecyclerView.Adapter<PayerAdapter.PayerViewHolder>() {
    inner class PayerViewHolder(val itemDataBinding:ItemPayerBinding):RecyclerView.ViewHolder(itemDataBinding.root)

    private var itemOnClickListener:ItemOnClickListener? = null

    fun setOnItemClickListener(listener:ItemOnClickListener){
        this.itemOnClickListener = listener
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PayerViewHolder {
        return PayerViewHolder(ItemPayerBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: PayerViewHolder, position: Int) {
        val entity = data[position]
        holder.itemDataBinding.tvName.text = "项目名称: ${entity.chargeType}"
        holder.itemDataBinding.money.text = "账单金额: ${entity.chargeAmount}元"
        holder.itemDataBinding.userName.text = "户主姓名: ${entity.payerName}"
        holder.itemDataBinding.tvPhone.text = "联系电话: ${entity.contactNumber}"
        holder.itemDataBinding.root.setOnClickListener {
            itemOnClickListener?.onClick(it,position)
        }
    }
    interface ItemOnClickListener{
        fun onClick(view: View,position: Int)
    }
}
class PayerTwoAdapter(private val data:List<Payer>):RecyclerView.Adapter<PayerTwoAdapter.PayerTwoViewModel>(){
    inner class PayerTwoViewModel(val itemDataBinding:ItemPayer1Binding):RecyclerView.ViewHolder(itemDataBinding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PayerTwoViewModel {
        return PayerTwoViewModel(ItemPayer1Binding.inflate(LayoutInflater.from(parent.context),parent,false))
    }

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: PayerTwoViewModel, position: Int) {

    }

}